import { defineStore } from 'pinia';

export const useshareStore = defineStore('share', {
   state: () => ({
      ischange: false,//路由跳转是否有修改
      storagetab:[],//处理关掉对应页签时候，路由keep-alie缓存的组件销毁
      comui:[],//自定义配置
      reset:false,//父组件重置后，子组件监听它也重置
      comdata:{}//监听父子组件之间共享的数据
   }),
   actions: {
      setischange(ischange) {
         this.ischange = ischange;
      },
      setstoragetab(tab,type='add') {
         if(type=='add'){
            if(this.storagetab.indexOf(tab)==-1){
               this.storagetab.push(tab);
            }
         }else if(type=='del'){
            this.storagetab.splice(this.storagetab.indexOf(tab), 1);
         }
      },
      setcomui(keyarr) {
         let key=keyarr[0];
         this.comui[key] =keyarr[1];
      },
      setreset(isset) {
         this.reset=isset;
      },
      setcomdata(key,data) {
         this.comdata[key]=data;
      },
   },
});
